package com.fjp.heartguard.app.ext

import android.widget.ImageView
import androidx.databinding.BindingAdapter
import coil.load
import coil.transform.RoundedCornersTransformation
import com.fjp.heartguard.R
import com.zhpan.bannerview.utils.BannerUtils.dp2px

@BindingAdapter(value = ["url"], requireAll = false)
fun setImageUri(imageView: ImageView, url: String) {
    imageView.load(url, builder = {
        allowHardware(false)
        this.error(R.drawable.avatar_default)
        this.placeholder(R.drawable.avatar_default)
    })
}

@BindingAdapter(value = ["avatarurl"], requireAll = false)
fun setAvatarImageUri(imageView: ImageView, avatarurl: String) {
    imageView.load(avatarurl, builder = {
        allowHardware(false)
        this.error(R.drawable.avatar_default)
        this.placeholder(R.drawable.avatar_default)
        transformations(RoundedCornersTransformation(dp2px(37f).toFloat()))
    })
}

